/* This file is part of BonQ - A simple HTTP-based messaging server.
 * Copyright (C) 2009 James Cook
 *
 * BonQ is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License, version 2, as published by the
 * Free Software Foundation.
 *
 * BonQ is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License, version 2,
 * for more details.
 *
 * You should have received a copy of the GNU General Public License, version
 * 2, along with BonQ.  If not, see:
 *
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */
package com.bonkabonka.queue;

/**
 * Abstract base of all queues.
 * 
 * @author jamesc
 */
public abstract class Queue
{
    private transient QueueBucket bucket = null;
    private String name = null;
    
    /**
     * Initialize the FIFO, attaching it to the specified bucket and assigning
     * it the given name.
     * 
     * @param bucket
     * @param name
     */
    public void init(QueueBucket bucket, String name)
    {
        this.bucket = bucket;
        this.name = name;
    }
    
    /**
     * Fetch the name assigned to the FIFO.
     * 
     * @return String containing the name
     */
    public String getName()
    {
        return name;
    }
    
    /**
     * Fetch the QueueBucket this FIFO resides in.
     * 
     * @return QueueBucket containing the Queue
     */
    public QueueBucket getBucket()
    {
        return bucket;
    }
    
    /**
     * Reconfigure the FIFO.  By default, attempted configuration changes are
     * ignored.
     * 
     * @param config String containing new configuration information
     * @return String containing status
     */
    public String configure(String config)
    {
        return "ERR: unsupported";
    }
    
    /**
     * Adds a message to the FIFO.
     * 
     * @param message String containing the message
     * @return String containing status
     */
    public abstract String push(String message);
    
    /**
     * Returns the top message from the FIFO without removing it.
     * 
     * @return String containing the message
     */
    public abstract String peek();

    /**
     * Returns and removes the top message from the FIFO.
     * 
     * @see #peek
     * 
     * @return String containing the message
     */
    public abstract String pull();
}
